<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>模拟即时聊天</title>

	<!--格式化json需要的js-->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-json/2.6.0/jquery.json.min.js"
			integrity="sha512-QE2PMnVCunVgNeqNsmX6XX8mhHW+OnEhUhAWxlZT0o6GFBJfGRCfJ/Ut3HGnVKAxt8cArm7sEqhq2QdSF0R7VQ=="
			crossorigin="anonymous"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jsonlint/1.6.0/jsonlint.min.js"
			integrity="sha512-6qbnCNQe7wVcBDvhNJT6lZsbDKHCQQBk7yOBQg4s/9GG812CknK0EEIqG2IS10XuNxIQNWjMJd6VLwwezICz6w=="
			crossorigin="anonymous"></script>

	<!--<script src="/socket/socket.io.js"></script>-->
	<script type="text/javascript" src="/static/wxshare/share/js/socket.io.js"></script>
	<style>
        input[type=text] {
            width: 820px;
            padding-left: 5px;
        }
	</style>


	<script>
		// 接口的链接
		//var appapi_url = 'http://192.168.101.133:8080/appapi/index.php';
		var appapi_url = 'https://s1.scbjxs.com/appapi/index.php';
		var h5api_url = 'https://s1.scbjxs.com';

		// socket的链接
		//var socket_url = "http://127.0.0.1:19967";
		//var socket_url = "http://www.zhibo.com:19967";
		//var socket_url = "http://192.168.101.133:19967";
		var socket_url = "http://s2.scbjxs.com:19967";
		//var socket_url = "http://s1.zhiboxiu.com.cn:19967";
		//var socket_url = "http://121.40.35.162:19967";
		var user_token;
		var user_id;
		var user_info;
		var user_live;
		var mobileid;
		var roomid;
		var liveuid;
		var stream;
		var socket = new io(socket_url);

		// 与服务器连接成功
		socket.on('connect', () => {
			mobileid = socket.id
			console.log('socket链接:' + socket_url)
			console.log('socket链接成功！' + socket.id)
		})

		// 与服务器连接成功
		socket.on('disconnect', () => {
			console.log('socket链接:断开')
			console.log('socket链接:断开成功！')
		})

		// 接受服务器消息
		socket.on('broadcastingListen', function (data) {
			//console.log(data[0]);
			//console.log(JSON.parse(data[0]).msg[0]);
			var listenMsg = JSON.parse(data[0]).msg[0];
			//console.log(listenMsg);
			console.log(JSON.stringify(listenMsg));

			// 如果是金花游戏
			if (listenMsg._method_ && listenMsg._method_ == 'jinhuaLiveGame') {
				$("#result_jinhuaLiveGame .show1").text(listenMsg.commit + '（action：' + listenMsg.action + '）')
				$("#result_jinhuaLiveGame .show2").text(listenMsg.ct)

			}
			if (listenMsg._method_ && listenMsg._method_ == 'jinhuaLiveGameEnd') {
				$("#result_jinhuaLiveGame .show3").text(listenMsg.ct)
			}
		});


		// 发送socket测试
		function sendSocket() {
			var msgString ={
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'startJinhuaHand',
						uid: '1074',
						roomnum: '1074',
						token: '66cf30fc0034f59868ff94099c9e1aab',
						commit: '开启金花游戏发送消息',
						ct: ''
					}
				]
			}
			socket.emit('broadcast', msgString);
			console.log('模拟发送消息', JSON.stringify(msgString));
		}

		// 进入直播间
		function enterRoom() {
			stream = document.getElementById("stream_room").value;
			roomid = document.getElementById("stream_roomid").value;
			liveuid = document.getElementById("stream_liveuid").value;
			if (!user_info) {
				alert('请先登录！')
				return false;
			}
			if (!roomid || !roomid || !liveuid) {
				alert('请填写内容！')
				return false;
			}

			// 直播间是独立的换成 需要请求后台设置当前登录用户的换成
			ajaxSocket('Live.enterRoom')

			// 直播间是独立的换成 需要请求后台设置当前登录用户的换成
			/*$.ajax({
				type: "post",
				url: appapi_url,
				data: {
					service: 'Live.enterRoom',
					uid: user_info.id,
					token: user_info.token,
					liveuid: liveuid,
					stream: stream,
					city: '',
					mobileid: mobileid
				},
				dataType: 'json',
				success: function (res) {
					if (res.ret == 200) {
						var msgString = {
							uid: user_info.id,
							roomnum: liveuid,
							stream: stream,
							nickname: user_info.user_nickname,
							equipment: 'pc',
							token: user_info.token
						}
						socket.emit('conn', msgString);
						console.log('进入直播间', msgString);
					} else {
						console.log("信息初始化失败，请刷新");
					}
				}
			});*/
		}

		// 登录
		function toLogin() {
			var textarea1 = document.getElementById("login_user");
			var textarea2 = document.getElementById("login_pass");
			var uid = textarea1.value;
			var pass = textarea2.value;
			$.ajax({
				cache: true,
				type: "POST",
				url: appapi_url,
				data: {service: 'Login.userLogin', country_code: 86, user_login: uid, user_pass: pass},
				dataType: 'json',
				async: false,
				error: function (request) {
					alert("登录错误！");
					return false;
				},
				success: function (res) {
					if (res.data.info) {
						user_info = res.data.info[0]
						user_token = user_info.token
						user_id = user_info.id
						console.log('登录成功 user:', user_info)
						console.log('登录成功 token:', user_token)
					}
				}
			});
		}

		// 向指定客户端发送消息
		function sendMsg() {
			var send_msg = document.getElementById("send_msg").value;
			if (!user_info) {
				alert('请先登录！')
				return false;
			}
			if (!user_live) {
				alert('请先进入直播间！')
				return false;
			}
			if (!send_msg) {
				alert('请填写内容！')
				return false;
			}

			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{

						_method_: 'SendMsg',
						ct: send_msg,

						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						/*
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',*/
					}
				]
			}
			socket.emit('broadcast', msgString);
			console.log('发生消息', msgString);
		}

		// 送礼
		function SendGift() {
			// 6a6fc84cda4a76bbc5a337d7d122c796
			var gift_token = document.getElementById("gift_token").value;
			if (!user_info) {
				alert('请先登录！')
				return false;
			}
			if (!user_live) {
				alert('请先进入直播间！')
				return false;
			}
			if (!gift_token) {
				alert('请填写内容！')
				return false;
			}

			var msgString1 = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'SendGift',
						ct: gift_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'SendGift',
						ct: '629509df02d852cba3ce34b262307c46',
						uname: '手机用户6785',
						uid: '1079',

						action: '0',
						msgtype: '1',
						level: '1',
						uhead: 'http://s1.scbjxs.com/default.jpg',
						evensend: '0',
						liangname: '0',
						vip_type: '0',
						roomnum: '1082',
						livename: '手机用户6788',
						paintedPath: [],
						paintedWidth: '0',
						paintedHeight: '0'
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		// 发红包
		function SendRed() {
			var gift_token = document.getElementById("gift_token").value;
			if (!user_info) {
				alert('请先登录！')
				return false;
			}
			if (!user_live) {
				alert('请先进入直播间！')
				return false;
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'SendRed',
						action: '0',
						msgtype: '0',
						uname: user_live.user_nickname,
						uid: user_live.id,
						ct: '在直播间发红包啦！快去抢哦～'
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		// 点亮
		function SendLight() {
			var gift_token = document.getElementById("gift_token").value;
			if (!user_info) {
				alert('请先登录！')
				return false;
			}
			if (!user_live) {
				alert('请先进入直播间！')
				return false;
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'SendMsg',
						ct: '我点亮了',
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',

						heart: '5'
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		// 系统消息
		function systemadmin() {
			var system_msg = document.getElementById("system_msg").value;
			socket.emit("systemadmin", {"token": "1234567", "content": system_msg});
		}

		// 警告消息
		function warningMsg() {
			var warning_msg = document.getElementById("warning_msg").value;
			var roomid = document.getElementById("stream_roomid").value;
			var liveuid = document.getElementById("stream_liveuid").value;
			socket.emit("warning", {"token": "1234567", "roomnum": liveuid, "content": warning_msg});
		}

		// 金花游戏：开启
		function startJinhuaHand() {
			var msgString = makeSocketMsg({}, 'startJinhuaHand', '', '开启金花游戏发送消息')
			socket.emit('broadcast', msgString);
			console.log('开启金花游戏发送消息', JSON.stringify(msgString));
		}

		// 金花游戏：投注
		function JinhuaBet() {
			let coin = document.getElementById("coin_JinhuaBet").value;
			let grade = document.getElementById("grade_JinhuaBet").value;
			let gameid = document.getElementById("gameid_JinhuaBet").value;
			if (!coin || !grade || !gameid) {
				alert('请填写内容！')
				return false;
			}
			if (!user_live) {
				alert('请先进入直播间！')
				return false;
			}


			let param = {
				service: "Game.JinhuaBet",
				uid: user_info.id,
				token: user_info.token,
				coin: coin,
				grade: grade,
				gameid: gameid
			};
			var msgString = makeSocketMsg({param: param}, 'urlRequest', '', '投注金花游戏发送消息')
			socket.emit('broadcast', msgString);
			console.log('投注金花游戏发送消息', JSON.stringify(msgString));
		}

		// 金花游戏：结束
		function endJinhuaHand() {
			var msgString = makeSocketMsg({}, 'endJinhuaHand', '', '结束金花游戏发送消息')
			socket.emit('broadcast', msgString);
			console.log('结束金花游戏发送消息', JSON.stringify(msgString));
		}

		// 切换房间收费
		function changeLive() {
			var gift_token = document.getElementById("gift_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'changeLive',
						ct: '我点亮了',
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',

						heart: '5'
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		// 更新映票
		function updateVotes() {
			var gift_token = document.getElementById("gift_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'updateVotes',
						ct: '我点亮了',
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',

						heart: '5'
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		// 发弹幕
		function SendBarrage() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'SendBarrage',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 踢人
		function KickUser() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'KickUser',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		// 超管关播
		function stopLive() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'stopLive',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		// 恢复发言
		function ResumeUser() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'ResumeUser',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		// 设置/取消管理员
		function setAdmin() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'setAdmin',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// StartEndLive
		function StartEndLive() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'StartEndLive',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 购买守护
		function BuyGuard() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'BuyGuard',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 主播和主播连麦
		function LiveConnect() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'LiveConnect',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 主播PK
		function LivePK() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'LivePK',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 系统通知
		function SystemNot() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'SystemNot',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		// 上、下庄
		function shangzhuang() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'shangzhuang',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 商品在直播间展示/不展示
		function goodsLiveShow() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'goodsLiveShow',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}

		//炸金花游戏
		function startGame() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'startGame',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 转盘
		function startRotationGame() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'startRotationGame',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 开心牛仔
		function startCattleGame() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'startCattleGame',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 海盗船长
		function startLodumaniGame() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'startLodumaniGame',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 二八贝
		function startShellGame() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'startShellGame',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 获取僵尸粉
		function requestFans() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'requestFans',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 直播间购物飘屏
		function shopGoodsLiveFloat() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			if (!barrage_token) {
				alert('请填写内容！')
			}
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'shopGoodsLiveFloat',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// 直播间购物飘屏
		function voiceRoom() {
			var barrage_token = document.getElementById("barrage_token").value;
			if (!user_info) {
				alert('请先登录！')
			}
			if (!user_live) {
				alert('请先进入直播间！')
			}
			/*if (!barrage_token) {
				alert('请填写内容！')
			}*/
			var msgString = {
				retcode: '000000',
				retmsg: 'ok',
				msg: [
					{
						_method_: 'voiceRoom',
						ct: barrage_token,
						uname: user_live.user_nickname,
						uid: user_live.id,

						action: '0',
						msgtype: '2',
						usertype: '30',
						isAnchor: '0',
						level: '16',
						liangname: '0',
						vip_type: '0',
						guard_type: '0',
					}
				]
			}

			socket.emit('broadcast', msgString);
			console.log('送礼', msgString);
		}


		// ajax 请求后 执行 socket 请求
		function ajaxSocket(service, data = {}, msgString = {}) {
			$default_data = {
				service: service,
				uid: user_info.id,
				token: user_info.token,
				liveuid: liveuid,
				stream: stream,
				city: '',
				mobileid: mobileid
			}
			$default_msg = {
				uid: user_info.id,
				roomnum: liveuid,
				stream: stream,
				nickname: user_info.user_nickname,
				equipment: 'pc',
				token: user_info.token
			}

			data = $.extend($default_data, data);
			$.ajax({
				type: "post",
				url: appapi_url,
				data: data,
				dataType: 'json',
				success: function (res) {
					if (res.ret == 200) {
						user_live = res.data.info[0];
						console.log(user_live)
						msgString = $.extend($default_msg, msgString);
						socket.emit('conn', msgString);
						console.log('进入直播间', msgString);
					} else {
						console.log("信息初始化失败，请刷新");
					}
				}
			});
		}


		// 制作发送、返回的消息
		function makeSocketMsg(info, method, ct, commit = '', action = 0) {
			info['_method_'] = method
			info['ct'] = ct
			info['uid'] = user_info.id
			info['stream'] = stream
			info['roomnum'] = roomid
			//info['uname'] = user_info.user_nickname
			//info['msgtype'] = 2
			//info['action'] = action
			info['token'] = user_info.token
			info['commit'] = commit
			console.log(info)
			return {"msg": [info], "retcode": "000000", "retmsg": "OK"};
		}

		// 制作发送、返回的消息
		function addSocketMsg(dataObj, method, ct, commit = '', action = 0) {
			dataObj['msg'][0]['ct'] = ct;
			dataObj['msg'][0]['_method_'] = method;
			dataObj['msg'][0]['uid'] = user_info.id
			//dataObj['msg'][0]['uname'] = user_info.user_nickname
			//dataObj['msg'][0]['msgtype'] = 2
			//dataObj['msg'][0]['action'] = action;
			dataObj['msg'][0]['token'] = user_info.token;
			dataObj['msg'][0]['commit'] = commit;
			return dataObj;
		}


	</script>

</head>

<body style="margin: auto;width:1020px;">
<div class="show">

	<h2>socket接口模拟测试</h2>
	<h3 style="color: red;">socket.io测试（按f12查看效果）</h3>

	<hr/>
	<h3>socket测试</h3>
	<input type="button" value="模拟发送socket" onclick="sendSocket();">

	<hr/>
	<h3>登录-进入直播间</h3>
	<!--登录-->
	<input type="button" value="用户登录（注意用户名）" onclick="toLogin();">
	<input type="text" id="login_user" value="13123456785" placeholder="请输入用户名" style="width:150px;"/>
	<input type="text" id="login_pass" value="123456" placeholder="请输入密码" style="width:150px;"/>
	<br/>

	<!--进入房间-->
	<input type="button" value="登录用户：进入直播间" onclick="enterRoom();">
	<input type="text" id="stream_room" value="" placeholder="请输入流名称" style="width:150px;"/>
	<input type="text" id="stream_liveuid" value="1078" placeholder="请输入主播ID" style="width:100px;"/>
	<input type="text" id="stream_roomid" value="1078" placeholder="请输入直播间ID" style="width:100px;"/>
	<br/>
	<br/>
	<hr/>

	<h3>直播间游戏操作：炸金花</h3>
	<input type="button" value="直播间游戏：炸金花游戏：投注" onclick="JinhuaBet();">
	<input type="text" id="gameid_JinhuaBet" value="" placeholder="请输入gameid" style="width:100px;"/>
	<input type="text" id="coin_JinhuaBet" value="10" placeholder="请输入投注金额" style="width:100px;"/>
	<input type="text" id="grade_JinhuaBet" value="1" placeholder="请输入投注位置" style="width:100px;"/>
	<br/>
	<input type="button" value="直播间游戏：炸金花游戏：开启" onclick="startJinhuaHand();">
	<br/>
	<input type="button" value="直播间游戏：炸金花游戏：结束" onclick="endJinhuaHand();">
	<br/>
	<div id="result_jinhuaLiveGame" style="background-color: #dbd1d1; padding:5px 10px;">
		<p>
			<span style="font-weight: bold">游戏提示：</span>
			<span class="show1"></span>
		</p>
		<p class="show2"></p>
		<p class="show3"></p>
	</div>
	<br/>
	<br/>
	<hr/>

	<h3>直播间操作：发送消息</h3>
	<hr/>

	<h1>以下功能未实现</h1>
	<hr/>

	<!--发送消息-->
	<input type="text" id="send_msg" value="发生的消息"/>
	<input type="button" value="发送消息" onclick="sendMsg();">
	<br/>

	<!--发送系统消息-->
	<input type="text" id="system_msg" value="发生的系统消息"/>
	<input type="button" value="发送系统消息" onclick="systemadmin();">
	<br/>

	<!--发送警告消息-->
	<input type="text" id="warning_msg" value="发生的警告消息"/>
	<input type="button" value="发送警告消息" onclick="warningMsg();">
	<br/>

	<!--发红包-->
	<input type="button" value="发红包" onclick="SendRed();">
	<input type="button" value="点亮" onclick="SendLight();">
	<br/>
	<hr/>


	<!--送礼-->
	<input type="text" id="gift_token" value="629509df02d852cba3ce34b262307c46" placeholder="礼物token"/>
	<input type="button" value="送礼" onclick="SendGift();">
	<br/>

	<br/><br/>


	<!--发弹幕-->
	<input type="text" id="barrage_token" value="" placeholder="礼物token"/>
	<input type="button" value="发弹幕" onclick="SendBarrage();">
	<br/>


	<input type="button" value="切换房间收费" onclick="changeLive();">
	<input type="button" value="更新映票" onclick="updateVotes();">
	<input type="button" value="踢人" onclick="KickUser();">
	<input type="button" value="超管关播" onclick="stopLive();">
	<input type="button" value="恢复发言" onclick="ResumeUser();">
	<input type="button" value="设置/取消管理员" onclick="setAdmin();">
	<input type="button" value="StartEndLive" onclick="StartEndLive();">
	<input type="button" value="购买守护" onclick="BuyGuard();">
	<input type="button" value="主播和主播连麦" onclick="LiveConnect();">
	<input type="button" value="主播PK" onclick="LivePK();">
	<input type="button" value="系统通知" onclick="SystemNot();">
	<input type="button" value="上、下庄" onclick="shangzhuang();">
	<input type="button" value="商品在直播间展示/不展示" onclick="goodsLiveShow();">
	<input type="button" value="炸金花游戏" onclick="startGame();">
	<input type="button" value="转盘" onclick="startRotationGame();">
	<input type="button" value="开心牛仔" onclick="startCattleGame();">
	<input type="button" value="海盗船长" onclick="startLodumaniGame();">
	<input type="button" value="二八贝" onclick="startShellGame();">
	<input type="button" value="获取僵尸粉" onclick="requestFans();">
	<input type="button" value="直播间购物飘屏" onclick="shopGoodsLiveFloat();">
	<input type="button" value="语音聊天室" onclick="voiceRoom();">
	<br/>

	<!--群发-->
	<input type="text" id="qunfa"
		   value='{"cmd":"groups@chat", "uid":"2", "username":"xxx", "group_id":"2", "say":"我对你说话了！！"}'/>
	<input type="button" value="群发" onclick="qunfa();">
	<br/>

	<!--个人聊天-->
	<input type="text" id="sifa"
		   value='{"cmd":"friend@chat", "uid":"2", "username":"xxx", "f_uid":"1", "say":"我对你说话了！！"}'/>
	<input type="button" value="个人聊天" onclick="sifa();">
	<br/>

	<!--测试消息-->
	<input type="text" id="receive" value='{"cmd":"test@receive", "username":"xxx", "say":"我对你说话了！！"}'/>
	<input type="button" value="测试消息" onclick="receive();">
	<br/>

	<!--测试消息-->
	<input type="text" id="receive2"
		   value='{"cmd":"test@receive", "username":"xxx", "mp3":"<?php echo $picturedata; ?>"}'/>
	<input type="button" value="测试音频消息" onclick="receive2();">
	<br/>

	<!--在线测试-->
	<textarea id="textarea">{"cmd":"friend@chat", "uid":"2", "username":"xxx", "f_uid":"1", "say":"我对你说话了！！"}</textarea><br/>


	<div>
		<input type="button" onclick="Test();" value="提交" style="margin-left: 350px;width: 100px;;float: left;">
		<input type="button" onclick="Clear();" value="清空记录" style="width: 100px;float: left;">
	</div>
	<br/><br/>

	<!--显示结果-->
	<div id="result"></div>
	<br/><br/><br/><br/>

</div>

<style>
    #result {
        display: block;
        padding: 9.5px;
        margin: 5px 0 10px;

        font-size: 16px;
        line-height: 30px;
        text-align: left;
        width: 950px;
        word-wrap: break-word;
        word-break: break-all;
    }

    #result p {
        background-color: #f5f5f5;
    }

    #textarea {
        font-size: 18px;
        line-height: 30px;
        height: 100px;
        width: 1020px;
        margin-bottom: 10px;
    }

    h2, h3, h4, h5 {
        margin: 15px;
        text-align: center;
    }

    input {
        font-size: 1rem;
        line-height: 30px;
        color: #666;
        border: 1px solid #dce4e6;
        margin: 4px;
    }

</style>
<!--描点：返回顶部-->
<a href="#top">
	<div style="position: fixed; width: 40px; height: 40px; background: rgb(0, 136, 204); cursor: pointer; bottom: 181px; right: 100px; border-radius: 10px;">
		<div style="width: 0px; height: 0px; margin: 0px auto; padding-top: 13px; border-style: solid; border-width: 0px 10px 10px; border-color: transparent transparent rgb(255, 255, 255);"></div>
	</div>
</a>

<!--描点：返回顶部-->
<a href="#bottom">
	<div style="position: fixed; width: 40px; height: 40px; background: rgb(0, 136, 204); cursor: pointer; top: 181px; right: 100px; border-radius: 10px;">
		<div style="width: 0px; height: 0px; margin: 0px auto; padding-top: 13px; border-style: solid; border-width: 0px 10px 10px; border-color: transparent transparent rgb(255, 255, 255);"></div>
	</div>
</a>
<lable id="bottom"></lable>
</body>


<script type="module">


	// 进入直播间
	/*socket.emit('conn', {
			uid: '1079',
			token: '0a1239b20780600c4984e633abd100b9',
			mobileid: 'af6f59afebf883593872e87a8bc1026c',
			liveuid: '1066',
			roomnum: '1066',
			stream: '1066_1701171522'
		});*/


</script>

</html>
